package edu.pku.sei.modeler.uml.commands.statemachine;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.uml.BehaviorStateMachines.Pseudostate;
import edu.pku.sei.modeler.model.uml.BehaviorStateMachines.State;
import edu.pku.sei.modeler.uml.commands.NestedElementDeleteCommand;

public class NestedStateDeleteCommand extends NestedElementDeleteCommand {

	public NestedStateDeleteCommand(MetaNode node, MetaNode fatherNode,
			boolean isDeletedFromDiagram) {
		super(node, fatherNode, isDeletedFromDiagram);
	}
	
	@Override
	public void deleteModelElement() {
		MetaModelElement modelElement = this.node.getModelElement();
		if (fatherNode.getModelElement() instanceof State) {
			State parentState = (State) fatherNode.getModelElement();
			if (modelElement instanceof State
					|| modelElement instanceof Pseudostate) {
				parentState.getOwnedMember().add(modelElement);
			}
		}
	}
	
	@Override
	public void undoDeleteModelElement() {
		if (fatherNode.getModelElement() instanceof State) {
			State parentState = (State) fatherNode.getModelElement();
			MetaModelElement modelElement = this.node.getModelElement();
			if (modelElement instanceof State
					|| modelElement instanceof Pseudostate) {
				parentState.getOwnedMember().remove(modelElement);
			}
		}
	}

}
